var schLocPage = (function ($) {
	var thisYM = ''
	var currYM = ''
	var locToday = '',startDate="",endDate=""
	var userPicker,weekPicker; //病区选择弹框和日期选择弹框
	var isToSch = false,isOverdue = false; //isOverdue超出修改期限
	var wardID = '',nurseid=""
	var wardArr,argParam,argInfo,locSchArr;//病区数组,排班参数 排班表信息 排班详情
	var zhiArr,xiuArr,allArr;//值班,休假和全部代码
	var lastSelect = ''
	$.init();
	$.plusReady(function () {
	    baseSetup();
	})
	if (!mui.os.plus) {
		baseSetup();
	}
	function createNewArrange(createBlock,saveBtn){
		if (!locSchArr) {
			mui.toast('请刷新')
			return
		}
		var ArgStatus = ''
		if (saveBtn) {
			ArgStatus = saveBtn.getAttribute('data-id')
		}
		var totalMark = $('#totalMark')[0].innerHTML.replace(/<br>/g,"「") 
		//ArgWardDR|病区Id^ArgStDate|开始日期^ArgEndDate|结束日期^ArgCrtUser|创建者user Id^ArgRemarks|排班表备注^ArgStatus|状态^rw|排班表Id^WardDesc|病区描述
		var parr1 = 'ArgWardDR|'+wardID+'^ArgStDate|'+startDate+'^ArgEndDate|'+endDate+'^ArgCrtUser|'+nurseid+
			'^ArgRemarks|'+totalMark+'^ArgStatus|^rw|^WardDesc|'+$('#locText')[0].innerText
		//护士person Id^行序号^分组Id^操作人user Id^行备注^行Id^负责床位 过个人员用@分隔
		var parr2 = ''
		mui.each(locSchArr,function (index,oneDict) {
			if (oneDict['PerID'] == undefined) {
				return
			}
			if (parr2 != "") {
				parr2 += '@'
			}
			var beds = oneDict['ArgPerBeds']!=undefined?oneDict['ArgPerBeds']:"";
			parr2 += oneDict['ArgPerDR']+'^'+oneDict['ArgPerSort']+'^'+oneDict['ArgGroupDR']+"^"+nurseid+'^^'+
				oneDict['ArgRowId']+'^'+beds;
		});
		
		var pdict = {'parr1':parr1,'parr2':parr2,'appFlag':'1'}
		var paramDict = {'method':'web.INMArgComm:SaveArgRows','params':JSON.stringify(pdict),'type':'Method'}
		//console.log(JSON.stringify(pdict))
		mui.DHCWebService(paramDict, function(result) {
			//console.log(JSON.stringify(result))
			var msg = parseInt(result['msg'])
			if (!isNaN(msg) && msg > 0) {
				getArrangeInfo(msg,createBlock)
				return;
			}
			mui.toast('操作失败');
		}, function(errorStr) {
			mui.toast(errorStr);
		});
	}
	
	function saveArrange(saveBtn){
		var ArgCrtUser = argInfo['ArgCrtUser'];
		var ArgStatus = argInfo['ArgStatus']
		var rw = argInfo['rw']
		if (saveBtn) {
			ArgStatus = saveBtn.getAttribute('data-id')
		}
		//console.log(ArgStatus)
		var totalMark = $('#totalMark')[0].innerHTML.replace(/<br>/g,"「") 
		//parr ArgWardDR|病区Id^ArgStDate|开始日期^ArgEndDate|结束日期^ArgCrtUser|创建者user Id^ArgRemarks|排班表备注^ArgStatus|状态^rw|排班表Id^WardDesc|病区描述
		var pdict = {'parr':'ArgWardDR|'+wardID+'^ArgStDate|'+startDate+'^ArgEndDate|'+endDate+'^ArgCrtUser|'+ArgCrtUser+
			'^ArgRemarks|'+totalMark+'^ArgStatus|'+ArgStatus+'^rw|'+rw+'^WardDesc|'+$('#locText')[0].innerText}
		var paramDict = {'method':'web.INMArgComm:SaveArrange','params':JSON.stringify(pdict),'type':'Method'}
		//console.log(JSON.stringify(pdict))
		mui.DHCWebService(paramDict, function(result) {
			//console.log(JSON.stringify(result))
			var msgTip = ''
			if (saveBtn) {
				msgTip = saveBtn.innerText
			}
			var msg = parseInt(result['msg'])
			if (!isNaN(msg) && msg > 0) {
				argInfo['ArgRemarks'] = totalMark
				argInfo['ArgStatus'] = ArgStatus
				if (!locSchArr) {
					getLocSchData()
				}
				if (saveBtn) {
					mui.toast(msgTip+'成功')
					$('#schStatus')[0].setAttribute('class','nurfont schStatus nur-status'+ArgStatus); //状态图标
					updateSaveBtnShow(ArgStatus)
				}
				return;
			}
			mui.toast(msgTip + result['msg']);
		}, function(errorStr) {
			mui.toast(errorStr);
		});
	}
	
	//排班参数
	function getArgParams(){
		var pdict = {'id':1} 
		var paramDict = {'method':'web.INMSetComm:GetArgParam','params':JSON.stringify(pdict),'type':'RecMethod'}
		//console.log(JSON.stringify(pdict))
		mui.DHCWebService(paramDict, function(result) {
			//console.log(JSON.stringify(result))
			if (result['msgcode'] != '1' || result['data'].length==0) {
				clearLocSchUI()
				showNullTip('哎呀,服务器逃跑了。<div id="refreshBtn">刷新试试</div>')
				return
			}
			hideNullTip()
			var dataDict = result['data']
			argParam = dataDict;
			initWeekMonth(dataDict);
		}, function(errorStr) {
			clearLocSchUI()
			showNullTip('哎呀,服务器逃跑了。<div id="refreshBtn">刷新试试</div>')
		});
	}
	//初始化日期
	function initWeekMonth(dataDict){
		if (dataDict['ArgPeriod'] == 'Week' && !weekPicker) {
			weekPicker = new dhcWeekPicker({
				'tapBtnId':'',
				'today':locToday,
				'mask':true
			},function(startStr,endStr,weekIndex,isHide){
				$('#locYM')[0].classList.remove('mui-active')
				if (isHide) {
					return;
				}
				$('#locDate')[0].innerHTML = '第'+weekIndex+'周'
				startDate = startStr;
				endDate = endStr;
				lastSelect = ''
				//清除底部排班弹出框内容
				mui('#schSlider .schItem.mui-active').each(function (index,element) {
					element.classList.remove('mui-active')
				});
				updateHeaderUI();
				clearLocSchUI();
				isExsitArg();//检查是否排班
			});
		}
	}
	//检查是否排班
	function isExsitArg(isLastWeek,lunCheckBlock){
		//console.log('isExsitArg')
		var pdict = {'parr':wardID+'^'+startDate}
		if (isLastWeek) {
			var lastWeekDate = getLastWeekStartDate(startDate)
			pdict = {'parr':wardID+'^'+lastWeekDate}
		}
		var paramDict = {'method':'web.INMArgComm:IsExsitArg','params':JSON.stringify(pdict),'type':'Method'}
		//console.log(JSON.stringify(pdict))
		mui.DHCWebService(paramDict, function(result) {
			// console.log(JSON.stringify(result))
			if (result['msgcode'] != '1') {
				if (!isLastWeek) {
					clearLocSchUI()
					showNullTip('哎呀,服务器逃跑了。<div id="refreshBtn">刷新试试</div>')
				}
				if (isLastWeek && lunCheckBlock) {
					plus.nativeUI.closeWaiting()
					return
				}
				return
			}
			var id = parseInt(result['msg'])
			if (isLastWeek && lunCheckBlock) {
				lunCheckBlock(id)
				return
			}
			if (id > 0) {
				if (isLastWeek&&isToSch) {
					mui.confirm('复制上周排班','温馨提示',['取消','复制'],function (e) {
						if (e.index == 1) {
							copyLastWeekData(id)
						}else{
							$('#saveBtn')[0].style.display = 'block'
							$('#commitBtn')[0].style.display = 'none'
							getLocSchData();
						}
					})
				}else{
					getArrangeInfo(id)
				}
			}else if (id == 0) {
				if (!isLastWeek&&isToSch) {
					isExsitArg(true) //本周未排班,检查上周班次
					return
				}
				if (isToSch) {
					// 上周也没排版的情况
					$('#saveBtn')[0].style.display = 'block'
					$('#commitBtn')[0].style.display = 'none'
				}
				
				getLocSchData();
			}
		}, function(errorStr) {
			if (!isLastWeek) {
				clearLocSchUI()
				showNullTip('哎呀,服务器逃跑了。<div id="refreshBtn">刷新试试</div>')
			}
			if (isLastWeek && lunCheckBlock) {
				plus.nativeUI.closeWaiting()
				return
			}
		});
	}
	//复制上周排班
	function copyLastWeekData(lastid){
		//ArgWardDR|病区Id^ArgStDate|开始日期^ArgEndDate|结束日期^ArgCrtUser|创建者user Id^ArgRemarks|排班表备注^ArgStatus|状态^rw|排班表Id^WardDesc|病区描述
		var parr = 'ArgWardDR|'+wardID+'^ArgStDate|'+startDate+'^ArgEndDate|'+endDate+'^ArgCrtUser|'+nurseid+
			'^ArgRemarks|^ArgStatus|^rw|^WardDesc|'+$('#locText')[0].innerText
		var pdict = {'lastid':lastid,'parr':parr}
		var paramDict = {'method':'web.INMArgComm:copyLastArg','params':JSON.stringify(pdict),'type':'Method'}
		//console.log(JSON.stringify(pdict))
		mui.DHCWebService(paramDict, function(result) {
			//console.log(JSON.stringify(result))
			var msg = parseInt(result['msg'])
			if (!isNaN(msg) && msg > 0) {//复制成功
				getArrangeInfo(msg)
				return;
			}
			mui.toast(result['msg']);
			getLocSchData()
		}, function(errorStr) {
			mui.toast('复制上周排班失败')
			getLocSchData()
		});
	}
	
	//排班表信息
	function getArrangeInfo(id,createBlock){
		var pdict = {'id':id}
		var paramDict = {'method':'web.INMArgComm:GetArrange','params':JSON.stringify(pdict),'type':'RecMethod'}
		//console.log(JSON.stringify(pdict))
		mui.DHCWebService(paramDict, function(result) {
			// console.log(JSON.stringify(result))
			if (result['msgcode'] != '1' || result['data'].length==0) {
				clearLocSchUI()
				showNullTip('哎呀,服务器逃跑了。<div id="refreshBtn">刷新试试</div>')
				return;
			}
			argInfo = result['data']
			var status = argInfo['ArgStatus'] //状态 N草稿 S保存未提交 R提交 A审核 B驳回
			// console.log('排班表状态:',status)
			$('#schStatus')[0].setAttribute('class','nurfont schStatus nur-status'+status); //状态图标
			//整体备注
			var markStr = argInfo['ArgRemarks']
			$('#totalMark')[0].innerHTML = markStr.replace(/「/g,"<br>")
			//是否超出可修改期限
			var SubmitDate = argInfo['ArgSubmitDate']
			if (status == 'R' && SubmitDate!=undefined && SubmitDate != "") { //提交 看是否超期
				isOverdue = isDateOverdue(SubmitDate,argParam['ArgUpdateDay'],locToday)
			}
			updateSaveBtnShow(status)
			if(status == 'R'){
				getLocSchData(createBlock)
			}
			
			if (isToSch) {
				var totalMarkBtn = $('#totalMarkBtn')[0]
				if (isOverdue) {
					totalMarkBtn.style.display = 'none'
				}else{
					totalMarkBtn.style.display = 'block'
				}
			}
		}, function(errorStr) {
			clearLocSchUI()
			showNullTip(errorStr+'。<div id="refreshBtn">刷新试试</div>')
		});
	}
	
	function getLocSchData(createBlock){
		//$('#locWrapper').scroll().scrollTo(0,0,100);
		var pdict = {'nurseid':nurseid,'parr':wardID+'^'+startDate+'^'+endDate}
		var paramDict = {'method':'web.INMArgComm:FindArrangeSubList','params':JSON.stringify(pdict),'type':'RecQuery'}
		//console.log(JSON.stringify(pdict))
		$.DHCWebService(paramDict, function(result) {
			locSchArr = result['data']
			//console.log(JSON.stringify(result));
			if (result['msgcode'] != '1') {
				clearLocSchUI()
				showNullTip(result['msg']+'。<div id="refreshBtn">刷新试试</div>')
				return
			}
			hideNullTip()
			updateLocSchUI(locSchArr)
			if (createBlock) {
				var trIndex=''
				var active = getActiveSchDom()
				if (active) {
					trIndex = active.parentNode.id.replace('row-','')
				}
				createBlock(argInfo,locSchArr,trIndex)
			}
		}, function(errorStr) {
			clearLocSchUI()
			showNullTip('哎呀,服务器逃跑了。<div id="refreshBtn">刷新试试</div>')
		});
	}
	function updateHeaderUI(){
		var trDom = $('#locHeadDate')[0]
		var html = '<td data-id="'+startDate+'">'+startDate.substring(startDate.length - 2,startDate.length)+'</td>'
		var date = startDate
		for (var i = 0; i < 5;i++) {
			date = getNextDay(date)
			html += '<td data-id="'+date+'">'+date.substring(date.length - 2,date.length)+'</td>'
		}
		html += '<td data-id="'+endDate+'">'+endDate.substring(endDate.length - 2,endDate.length)+'</td>'
		trDom.innerHTML = html
	}
	
	function updateLocSchUI(dataArr){
		var html = ''
		mui.each(dataArr,function (index,oneDict) {
			if (oneDict['PerID'] == undefined) {
				html += '<tr><td colspan="8" class="groupName">'+oneDict['PerName'];
				if (oneDict['bedCodes']!="") {
					html += '（'+oneDict['bedCodes']+'）';
				}
				html += '</td></tr>';
				return;
			}
			html += '<tr id="row-'+index+'" data-PerID="'+oneDict['PerID']+'" class="tr-nur"><td>'+oneDict['PerName'].replace(oneDict['PerID'],"")+'</td>';
			mui('#locHeadDate td').each(function (index2,headTd) {
				var date = headTd.getAttribute('data-id')
				html +=getOneSchHtml(oneDict,date)
			})
			html+='</tr>';
		})
		$('#locBody')[0].innerHTML = html;
		var lastSelectDom = $(lastSelect)[0]
		if (lastSelectDom) {
			mui.trigger(lastSelectDom,'tap')
		}else{
			lastSelect = ''
		}
	}
	
	/*//3943」N1『16:00-次日00:00「3944」休『%% 
	* 解析:id」班次描述及备注『一段时间;二段时间;三段时间「第二个班次……%请假班次描述%意愿排班申请id」班次描述「第二个意愿排班……
	* 先用%分割:0为已排班次信息,1为请假信息,2为意愿排班信息
	* 对于已排班次信息:多个班次之间用「分割,单个班次内用」分割,0为已排班次id,1为已排班次其他信息
	* 对于意愿排班信息:多个意愿排班用「分割, 单个班次内用」分割,0为意愿排班申请id,1为班次描述
	* 有请假信息 该单元格不允许添加排班  有意愿排班 点击的时候需要弹出审核框
	* //#0051FF!#3CFF00!@#0AF244!
	* 解析: 字体颜色!背景色 多个班次用@分隔
	*/
	function getOneSchHtml(oneDict,date){
		var str = oneDict['AppDate'+date]
		var colorStr = oneDict['Color'+date]
		var isHasMark = oneDict['AppRemark'+date]
		var html = ''
		str=!str?"":str
		colorStr=!colorStr?"":colorStr
		mui.each(str.split('%'),function (schIndex,oneSch) {
			var arr = oneSch.split('「')
			var colorArr = colorStr.split('@')
			mui.each(arr,function (index,oneStr) {
				var colorHtml = ''
				if (schIndex==0&& colorArr[index]!=undefined && colorArr[index] != "") {
					var oneColorArr = colorArr[index].split('!')
					colorHtml = 'style="'
					if (oneColorArr[1] != '') {
						colorHtml += 'background: '+oneColorArr[1]+';'
					}
					if (oneColorArr[0] != '') {
						colorHtml += 'color: '+oneColorArr[0]+';'
					}
					colorHtml += '"'
				}else if (schIndex == 2) {
					colorHtml = 'style="color: #CCCCCC;"'
				}
				var tmpArr = oneStr.split('」')
				var textStr = ''
				var mainStr = tmpArr[1]
				if (mainStr != undefined && mainStr != "") {
					var mainArr = mainStr.split('『')
					html += '<div '+colorHtml+'>'+mainArr[0]+'、</div>';
				}
			})
		})
		
		html = html.replace(/(.*)、</, '$1<');
		var markClass = ''
		if (isHasMark == 'Y') {
			markClass = ' nurfont nur-zhushi'
		}
		return '<td data-day="'+date+'" data-sch="'+str+'" class="schText'+markClass+'">'+html+'</td>'
	}
	
	function schTextTapped(){
		if (!isToSch) {//科室排班 点击 查询班次详情
			getLocChosenSchData(this)
			return
		}
		if (isOverdue) {
			mui.toast('已超出修改时限')
			return
		}
		var schStr = this.getAttribute('data-sch')
		var schArr = schStr.split('%')
		var holiday = schArr[1] ;//请假
		if (holiday && holiday != "") {
			mui.toast('已请假,不能再添加班次哦')
			return
		}
		var active = getActiveSchDom();
		if (active) {
			active.classList.remove('mui-active')
		}
		
		var yiYuan = schArr[2] ;//有意愿班次要先弹出审批框
		if (yiYuan && yiYuan != "") {
			lastSelect = ''
			if (!argInfo) {
				mui.toast('请先保存排班')
				mui('#schSlider .schItem.mui-active').each(function (index,element) {
					element.classList.remove('mui-active')
				});
				return
			}
			showApprovePopo(this,yiYuan);
			return
		}
		this.classList.add('mui-active')
		lastSelect = '#locBody tr[data-PerID="'+this.parentNode.getAttribute('data-PerID')+'"] td[data-day="'+this.getAttribute('data-day')+'"]';
		updateDownAreaSelect(schStr)
		upDownBtnTapped('show')
	}
	function updateDownAreaSelect(schStr){
		mui('#schSlider .schItem.mui-active').each(function (index,element) {
			element.classList.remove('mui-active')
		});
		mui.each(schStr.split('%'),function (cateIndex,oneCate) {
			if (cateIndex == 2 || oneCate == "") {//0为班次,1位请假(个人走的请假流程),2为未审批的个人意愿班次
				return
			}
			var arr = oneCate.split('「') //多个班次分隔
			mui.each(arr,function (schIndex,oneSch) {
				if (oneSch == "") return
				var tmpArr = oneSch.split('」')
				var mainStr = tmpArr[1]
				var mainArr = mainStr.split('『')
				mui('#schSlider .schItem[data-desc="'+mainArr[0]+'"]').each(function (index,element) {
					element.classList.add('mui-active')
				})
			})
		})
	}
	// 点击底部的值班/休班和全部区域内的班次时的快排
	function onePersonQuickSch(){
		var active = getActiveSchDom();
		if (!active) {
			mui.toast('请先选择单元格')
			return
		}
		var dom = this;
		if (!dom) {
			mui.toast('点击要添加的班次')
			return
		}
		var trIndex = active.parentNode.id.replace('row-','')
		var perInfo = locSchArr[trIndex]
		var ArgCrtUser = nurseid,ArgStatus = 'N',rw = ''
		if (argInfo) {
			ArgCrtUser = argInfo['ArgCrtUser'];
			ArgStatus = argInfo['ArgStatus']
			rw = argInfo['rw']
		}else{
			createNewArrange(function(){
				mui.trigger(dom,'tap')
			})
			return;
		}
		var currDay = active.getAttribute('data-day');
		var markStr = $('#totalMark')[0].innerHTML.replace(/<br>/g,"「") 
		var parr1 = 'ArgWardDR|'+wardID+'^ArgStDate|'+startDate+'^ArgEndDate|'+endDate+'^ArgCrtUser|'+ArgCrtUser+'^ArgRemarks|'+markStr+
			'^ArgStatus|'+ArgStatus+'^rw|'+rw+'^WardDesc|'+$('#locText')[0].innerText
		var parr2 = 'ArgPerDR|'+perInfo['ArgPerDR']+'^ArgPerSort|'+perInfo['ArgPerSort']+'^ArgGroupDR|'+perInfo['ArgGroupDR']+
			'^ArgWorkRemark|^rw|'+perInfo['ArgRowId']+'^ArgPerBeds|'+perInfo['ArgPerBeds']
		var scrollId = dom.parentNode.id;
		var domIndex = dom.getAttribute('data-index')
		var currDict = allArr[domIndex]
		if (scrollId == 'zhiScroll') {
			currDict = zhiArr[domIndex]
		}else if (scrollId == 'xiuScroll') {
			currDict = xiuArr[domIndex]
		}
		if (!currDict) {
			return
		} 
		var domRw = currDict['rw']
		var parr3 = domRw+'^'+currDay;//班次id^日期
		var pdict = {'parr1':parr1,'parr2':parr2,'parr3':parr3}
		//console.log(JSON.stringify(pdict))
		plus.nativeUI.showWaiting('正在排班', {modal: false});
		var paramDict = {'method':'web.INMArgComm:QuickArg','params':JSON.stringify(pdict),'type':'Method'}
		$.DHCWebService(paramDict, function(result) {
			// console.log(JSON.stringify(result))
			plus.nativeUI.closeWaiting()
			var msg = parseInt(result['msg'])
			if (!isNaN(msg) && msg > 0) {//保存成功
				if (perInfo['ArgRowId'] == "") {
					getLocSchData();
				}
				var fontColor = currDict['PostFontColor']
				var bgColor = currDict['PostBgColor']
				var colorHtml = 'style="'
				if (fontColor != "") {
					colorHtml += 'color:'+fontColor+';'
				}
				if (bgColor != "") {
					colorHtml += 'background:'+bgColor+';'
				}
				colorHtml += '"'
				active.innerHTML = '<div '+colorHtml+'>'+dom.innerText+'</div>';
				perInfo['Color'+currDay] = msg+'」'+dom.innerText+'『%%' ;//"4858」P『07:30-11:30;14:00-18:00%%",
				perInfo['AppDate'+currDay] = fontColor + '!'+bgColor
				perInfo['AppRemark'+currDay] = 'N'
				locSchArr[trIndex] = perInfo
				active.setAttribute('data-sch',perInfo['Color'+currDay]);
				active.classList.remove('nur-zhushi');
				active.classList.remove('nurfont');
				mui('#schSlider .schItem.mui-active').each(function (index,element) {
					element.classList.remove('mui-active')
				});
				mui('#schSlider .schItem[data-desc="'+dom.getAttribute('data-desc')+'"]').each(function (index,element) {
					element.classList.add('mui-active')
				})
				gotoNextTd(active,trIndex)
			}else{
				mui.toast(result['msg'])
			}
		}, function(errorStr) {
			plus.nativeUI.closeWaiting()
			mui.toast('请重试')
		});
	}
	// 点击组合名称的排班,只会给没有排班的排上,已经排班的不会替换
	function onePersonZuHeSch(){
		
		var active = getActiveSchDom();
		if (!active) {
			mui.toast('请先选择单元格')
			return
		}
		var dom = this;
		if (!dom) {
			mui.toast('请点击组合')
			return
		}
		plus.nativeUI.showWaiting('正在排班', {modal: false});
		var trIndex = active.parentNode.id.replace('row-','')
		var perInfo = locSchArr[trIndex]
		var ArgCrtUser = nurseid,ArgStatus = 'N',rw = ''
		if (argInfo) {
			ArgCrtUser = argInfo['ArgCrtUser'];
			ArgStatus = argInfo['ArgStatus']
			rw = argInfo['rw']
		}else{
			createNewArrange(function(){
				mui.trigger(dom,'tap')
			})
			return;
		}
		var currDay = active.getAttribute('data-day');
		var markStr = $('#totalMark')[0].innerHTML.replace(/<br>/g,"「") 
		var parr1 = 'ArgWardDR|'+wardID+'^ArgStDate|'+startDate+'^ArgEndDate|'+endDate+'^ArgCrtUser|'+ArgCrtUser+'^ArgRemarks|'+markStr+
			'^ArgStatus|'+ArgStatus+'^rw|'+rw+'^WardDesc|'+$('#locText')[0].innerText
		var parr2 = 'ArgPerDR|'+perInfo['ArgPerDR']+'^ArgPerSort|'+perInfo['ArgPerSort']+'^ArgGroupDR|'+perInfo['ArgGroupDR']+
			'^ArgWorkRemark|^rw|'+perInfo['ArgRowId']+'^ArgPerBeds|'+perInfo['ArgPerBeds']
		//console.log(dom.getAttribute('data-id'));
		var parr3 = dom.getAttribute('data-id')+'^'+currDay;//组合id^日期
		var pdict = {'parr1':parr1,'parr2':parr2,'parr3':parr3}
		//console.log(JSON.stringify(pdict))
		var paramDict = {'method':'web.INMArgComm:SavePostGroup','params':JSON.stringify(pdict),'type':'Method'}
		$.DHCWebService(paramDict, function(result) {
			//console.log(JSON.stringify(result))
			plus.nativeUI.closeWaiting();
			var msg = parseInt(result['msg'])
			if (!isNaN(msg) && msg > 0) {//保存成功
				lastSelect = '#locBody tr[data-PerID="'+active.parentNode.getAttribute('data-PerID')+'"] td[data-day="'+active.getAttribute('data-day')+'"]';
				getLocSchData()
			}else{
				mui.toast(result['msg']);
			}
		}, function(errorStr) {
			plus.nativeUI.closeWaiting();
			mui.toast('请重试')
		});
	}
	
	//查询科室排班信息后的单人单天的排班信息
	function getLocChosenSchData(dom){
		var index = dom.parentNode.id.split('-')[1]
		var oneDict = locSchArr[parseInt(index)]
		var dateStr = dom.getAttribute('data-day')
		var perid = oneDict['ArgPerDR']
		var pdict = {'perId':perid,'date':dateStr,'appFlag':'1','appRet':''}
		//console.log(JSON.stringify(pdict))
		var paramDict = {'method':'web.INMArgComm:GetPerDayArgInfo','params':JSON.stringify(pdict),'type':'MethodNoFilter'}
		$.DHCWebService(paramDict, function(result) {
			//console.log(JSON.stringify(result))
			$('#perInfo')[0].innerHTML = oneDict['PerName'].replace(oneDict['PerID'],"")+ ' '+dateStr
			var post = result['data']['Post']
			if (!post) {
				$('#schInfo')[0].innerHTML = '';
				mui('#locSchPopo').popover('toggle');
				return
			}
			var html = ''
			for (var i = 0; i < post.length; i++) {
				var onePost = post[i]
				var timeStr = onePost['StTime1']+' - '+onePost['EndTime1']
				if (onePost['StTime2']) {
					timeStr += ';' + onePost['StTime2']+' - '+onePost['EndTime2']
				}
				if (onePost['StTime3']) {
					timeStr += ';' + onePost['StTime3']+' - '+onePost['EndTime3']
				}
				html +='<div class="oneSchArea">'+
					'<div class="oneSchText">'+onePost['PostDesc']+
					'<div class="oneSchTime">（ '+timeStr+' ）</div></div>'+
					'<div class="oneSchMark">备注: '+onePost['Remark']+'</div></div>'
			}
			$('#schInfo')[0].innerHTML = html;
			mui('#locSchPopo').popover('toggle');
		}, function(errorStr) {
			mui.toast('请重试')
		});
	}
	
	function showApprovePopo(tdDom,yiYuan){
		$('#moreSchPopover')[0].classList.remove('dhc-active')
		var tr = tdDom.parentNode
		$('#applyer')[0].innerHTML = tr.querySelector('td').innerText
		var trIndex = tr.id.replace('row-','')
		var perInfo = locSchArr[trIndex]
		var yiYuanStr = ""
		var arr = yiYuan.split('「') //多个班次
		mui.each(arr,function (index,oneStr) {
			var tmpArr = oneStr.split('」')
			var textStr = ''
			var mainStr = tmpArr[1]
			if (mainStr != undefined && mainStr != "") {
				var mainArr = mainStr.split('『')
				yiYuanStr += '<div class="oneWish" data-id="'+tmpArr[0]+'">' +mainArr[0] +'</div>';
			}
		});
		
		$('#approvePopo')[0].setAttribute('data-parr',argInfo['rw']+'^'+perInfo['ArgRowId'])
		$('#applySch')[0].innerHTML = yiYuanStr;
		var firstWish = $('#applySch')[0].querySelector('.oneWish')
		firstWish.classList.add('dhc-active');
		
		getWishArrangeInfo(firstWish.getAttribute('data-id'))
		mui.each($('#applySch')[0].querySelectorAll('.oneWish'),function (index,element) {
			element.addEventListener('tap',function(){
				var oldActive = $('#applySch .oneWish.dhc-active')[0]
				if (oldActive) {
					oldActive.classList.remove('dhc-active')
				}
				this.classList.add('dhc-active')
				getWishArrangeInfo(this.getAttribute('data-id'))
			})
		});
	}
	function getWishArrangeInfo(id){
		$('#applySchTime')[0].innerHTML = ''
		$('#applySchMark')[0].innerHTML = '';
		$('#wishAction')[0].setAttribute('data-id','1')
		$('#wishAction .mui-switch')[0].classList.add('mui-active')
		var pdict = {'id':id}
		var paramDict = {'method':'web.INMArgComm:getWishArrange','params':JSON.stringify(pdict),'type':'RecMethod'}
		mui.DHCWebService(paramDict, function(result) {
			//console.log(JSON.stringify(result))
			var dataDict = result.data
			$('#applySchTime')[0].innerHTML = dataDict['ArgTime'];
			$('#applySchMark')[0].innerHTML = dataDict['Remark'];
			$('#approvePopo').popover('show')
			
		}, function(errorStr) {
		 	mui.toast('请重试')
		});
	}
	function approveYiYuanApply(){
		var classStr = this.getAttribute('class')
		var type = 'B'
		if (classStr.indexOf('passBtn') != -1) {
			type = 'A'
		}
		var parr =  $('#applySch .oneWish.dhc-active')[0].getAttribute('data-id')+'^'+nurseid+'^'+type+'^'+
			wishAction.getAttribute('data-id')+'^'+$('#approvePopo')[0].getAttribute('data-parr')
		
		var pdict = {'parr':parr} //申请Id^审批人id^状态^类型^排班表^排班行
		var paramDict = {'method':'web.INMArgComm:AuditWishArrange','params':JSON.stringify(pdict),'type':'Method'}
		//console.log(JSON.stringify(pdict))
		mui.DHCWebService(paramDict, function(result) {
			//console.log(JSON.stringify(result))
			if (result['msg'] != '1') {
				mui.toast(result['msg'])
				return
			}
			getLocSchData()
			$('#approvePopo').popover('toggle')
		}, function(errorStr) {
			mui.toast('审批失败')
		});
	}
	
	//删除班次
	function deleteOneSch(){
		var active = getActiveSchDom()
		var dateStr = active.getAttribute('data-day')
		var index = active.parentNode.id.split('-')[1]
		var oneDict = locSchArr[parseInt(index)]
		var perName = oneDict['PerName'].replace(oneDict['PerID'],"")
		var msg = '确认删除 '+perName+' '+dateStr+'的班次吗'
		var perid = oneDict['ArgPerDR']
		mui.confirm(msg,'删除提示',['取消','确认'],function (e) {
			if (e.index == 1) {
				deleteAction(active)
			}
		})
		
	}
	function deleteAction(active){
		var str = active.getAttribute('data-sch')
		var idStr=""
		mui.each(str.split('%'),function (schIndex,oneSch) {
			if (oneSch=='') {
				return
			}
			mui.each(oneSch.split('「'),function (index,oneStr) {
				if (oneStr == '') {
					return
				}
				var tmpArr = oneStr.split('」')
				if (idStr != '') {
					idStr += ','
				}
				idStr += tmpArr[0]
			});
		});
		var pdict = {'parr':idStr}
		var paramDict = {'method':'web.INMArgComm:DeleteArgSubById','params':JSON.stringify(pdict),'type':'Method'}
		//console.log(JSON.stringify(pdict))
		mui.DHCWebService(paramDict, function(result) {
			//console.log(JSON.stringify(result))
			if (result['msg'] != '1') {
				mui.toast(result['msg'])
				return
			}
			active.innerHTML = ''
			active.setAttribute('data-sch','')
			active.classList.remove('nur-zhushi');
			active.classList.remove('nurfont');
			var currDay = active.getAttribute('data-day')
			var trIndex = active.parentNode.id.replace('row-','')
			var perInfo = locSchArr[trIndex]
			perInfo['Color'+currDay] = '%%' ;
			perInfo['AppDate'+currDay] = '!'
			perInfo['AppRemark'+currDay] = 'N'
			locSchArr[trIndex] = perInfo
			mui('#schSlider .schItem.mui-active').each(function (index,element) {
				element.classList.remove('mui-active')
			});
		}, function(errorStr) {
			mui.toast('删除失败')
		});
	}
	
	function baseSetup(){
		if (!$('#slider')[0]) {
			isToSch = true
		}
		var perInfo = app.getState()
		nurseid=perInfo['loginID']
		locToday = getCurrentDeviceDay()
		$('#locText')[0].innerHTML = perInfo['loginWardDesc'];
		$('#locText')[0].setAttribute('data-id',wardID)
		var self = plus.webview.currentWebview()
		if (self.wardID != undefined) {
			wardID = self.wardID
			$('#locText')[0].innerHTML = self.wardDesc
		}else{
			wardID = perInfo['loginWardId']
			$('#locText')[0].innerHTML = perInfo['loginWardDesc'];
			if(wardID == undefined || wardID == '') {
				$('#locText')[0].innerHTML = '请选择'
			}
		}
		$('#locText')[0].setAttribute('data-id',wardID)
		$('.mui-scroll-wrapper').scroll({
			bounce: true,
			indicators: false, //是否显示滚动条
		});
		$('#nullTip').on('tap', '#refreshBtn', function(){
			if (!argParam) { //总信息
				getArgParams()
			}else if (!argInfo) { //排班表信息
				isExsitArg()
			}else if (!locSchArr) { //排班详情
				getLocSchData()
			}
		});
		getArgParams()
		$('.locDateName').on('tap', '#locYM', function() {
			if ($('#moreSchPopover')[0]) {
				$('#moreSchPopover')[0].classList.remove('dhc-active')
			}
			this.classList.add('mui-active')
			if (weekPicker) {
				weekPicker.pickerShow(startDate,endDate)
			}else{
				getArgParams()
			}
		});
		
		$('.locDateName').on('tap', '#locName', getAllWards);
		// 选择病区中的取消和确定按钮
		mui('body').on('tap','.mui-poppicker-header > button',function(e){
			$('#locName')[0].classList.remove('mui-active')
		});
		mui('#locBody').on('tap','.schText',schTextTapped);
		//科室排班查询某人某天排班详情弹框的关闭按钮
		mui('#locSchPopo').on('tap','#locSchClose',function(){
			mui('#locSchPopo').popover('toggle')
		}) 
		if (!isToSch) {
			return;
		}
		getPostData('P'); //获取排班班次
		getPostData('H'); //获取休班班次
		getPostData(''); //获取休班班次
		getCombineData(); //获取排班组合列表
		mui('#schSlider').on('tap','.schItem',onePersonQuickSch);
		mui('#schSlider').on('tap','li',onePersonZuHeSch);
		//mui.trigger(nextTd,'tap')
		mui('body').on('tap','.saveBtn',function(){
			var btn = this
			if (!argInfo) {
				createNewArrange(function(){},btn)
				return;
			}
			saveArrange(btn)
		});
		
		$('#addCombine')[0].addEventListener('tap',function(){
			var webview = plus.webview.create('nurSchZuHeAdd.html', 'nurSchZuHeAdd', {
				background: '#fff',
				statusbar: {
					background: '#fff'
				}
			},{'nurseid':nurseid,'wardID':wardID,'type':'loc'});
			webview.show('fade-in');
		})
		// 审批意愿班次的关闭按钮
		mui('.mui-popover').on('tap','.mui-icon-closeempty',function(){
			$('#approvePopo').popover('toggle')
		})
		// 审批意愿班次的同意
		mui('.mui-popover').on('tap','.passBtn',approveYiYuanApply) 
		// 审批意愿班次的拒绝
		mui('.mui-popover').on('tap','.denyBtn',approveYiYuanApply) 
		mui('.mui-popover').on('toggle','#wishAction .mui-switch',function(event){
			var status = event.detail.isActive?'1':'0'
			$('#wishAction')[0].setAttribute('data-id',status)
		});
		
		// 选择病区中的背景
		mui("body").on("tap",".mui-backdrop",function(){
			$('#locName')[0].classList.remove('mui-active')
		})
		// 底部功能按钮 
		mui(".schActionArea").on("tap",".funBtn",schFuncBtnsTapped);
		
		//底部的更多弹框的列表
		mui(".moreSchPopover").on("tap","li",function(){
			var rw = ''
			if (argInfo) {
				rw = argInfo['rw']
			}
			var page = this.getAttribute('data-page');
			var extras={'wardID':wardID,'wardDesc':$('#locText')[0].innerText,'startDate':startDate,'endDate':endDate,'rw':rw,'isOverdue':isOverdue,'nurseid':nurseid}
			if(page == 'nurSchPerSet'){
				extras['argInfo'] = argInfo
				extras['locSchArr'] = locSchArr;
			}
			
			if (page == 'nurSchLun') {
				if (isOverdue) {
					mui.toast('已超出修改期限,无法轮排')
					return
				}
				
				plus.nativeUI.showWaiting('检查上周排班')
				isExsitArg(true,function(lastId){
					plus.nativeUI.closeWaiting()
					if (lastId <=0) {
						mui.toast('上周没有排班数据,无法轮排')
						
						return
					}
					var webview = plus.webview.create(page+'.html', page, {
						background: '#fff',
						statusbar: {
							background: '#fff'
						}
					},{'sourceData':extras});
				});
				return;
			}
			if (page && page !="") {
				var webview = plus.webview.create(page+'.html', page, {
					background: '#fff',
					statusbar: {
						background: '#fff'
					}
				},{'sourceData':extras});
				webview.show('fade-in');
				if (page == 'nurSchPerSet') {
					webview.addEventListener('close',function(){
						getLocSchData()
					})
				}
			}
		});
		
		var schSlider = document.getElementById('schSlider');
		schSlider.addEventListener('slide', function(event) {
			var index = event.detail.slideNumber;
			$('#sliderIndicator .mui-indicator[data-index="'+index+'"]')[0].classList.add('mui-active');
		});
		mui("#sliderIndicator").on("tap",".mui-indicator",function(){
			var oldActive = $('#sliderIndicator .mui-indicator.mui-active')[0];
			if (oldActive) {
				if (oldActive == this) {
					return
				}
				oldActive.classList.remove('mui-active')
			}
			var newIndex = parseInt(this.getAttribute('data-index'))
			this.classList.add('mui-active')
			mui('#schSlider').slider().gotoItem(newIndex,100)
		});
		
		//护士长排班编辑整体备注弹框的关闭按钮
		mui('#totalMarkPopo').on('tap','.totalMarkClose',function(){
			$('#totalMark')[0].innerHTML = $('#totalMarkEdit')[0].value.replace(/\n/g,'<br>').replace(/\r/g,'<br>');
			mui('#totalMarkPopo').popover('toggle')
			//保存一次
			if (!argInfo) {
				createNewArrange(function(){})
				return;
			}
			saveArrange()
		}) 
		//整体备注编辑按钮
		mui('#locWrapper').on('tap','#totalMarkBtn',function(){
			$('#totalMarkEdit')[0].value = $('#totalMark')[0].innerText
			mui('#totalMarkPopo').popover('toggle')
			$('#moreSchPopover')[0].classList.remove('dhc-active')
		}) 
	}
	function getAllWards(){
		if ($('#moreSchPopover')[0]) {
			$('#moreSchPopover')[0].classList.remove('dhc-active')
		}
		var locDom = $('#locName')[0]
		locDom.classList.add('mui-active')
		if (wardArr) {
			userPicker.show(pickerWard);
			return
		}
	
		var pdict = {'nurseid':nurseid}
		var paramDict = {'method':'web.INMDataLimit:FindRoleWardList','params':JSON.stringify(pdict),'type':'RecQuery'}
		$.DHCWebService(paramDict, function(result) {
			//console.log(JSON.stringify(result))
			wardArr = result['data']
			for (var i = 0; i < wardArr.length; i++) {
				wardArr[i]['text'] = wardArr[i]['WardDesc']
			}
			
			userPicker = new $.PopPicker();
			userPicker.setData(wardArr)
			userPicker.show(pickerWard);
			
		}, function(errorStr) {
			mui.toast('请重试')
			locDom.classList.remove('mui-active')
		});
	}
	function pickerWard(items){
		var dict = items[0]
		$('#locText')[0].innerHTML = dict['text'];
		$('#locText')[0].setAttribute('data-id',dict['rw']);
		if (wardID == dict['rw']) {
			getLocSchData(); //刷新数据
		}else{
			wardID =  dict['rw'];
			clearLocSchUI()
			zhiArr=undefined;
			xiuArr=undefined;
			allArr=undefined;
			if (isToSch) {
				getPostData('P'); //获取排班班次
				getPostData('H'); //获取休班班次
				getPostData(''); //获取休班班次
				getCombineData(); //获取排班组合列表
			}
			isExsitArg() //是否存在排班
		}
	}
	//type P:排班 H:休假 S:特殊 意愿排班传P即
	function getPostData(type){
		var scrollId= 'allScroll'
		if (type == 'P') {
			scrollId="zhiScroll"
		}else if (type == 'H') {
			scrollId="xiuScroll"
		}
		var pdict = {"start":0,'limit':"",'parr':'^'+wardID+'^'+type} //P:排班 H:休假 S:特殊
		var paramDict = {'method':'web.INMDBComm:FindWardPostList','params':JSON.stringify(pdict),'type':'RecQuery'}
		//console.log(JSON.stringify(pdict))
		$.DHCWebService(paramDict, function(result) {
			//console.log(JSON.stringify(result))
			if (result['msgcode'] != '1') {
				mui.toast(result['msg'])
				$('#'+scrollId)[0].innerHTML = ''
				return
			}
			var dataArr = result['data']
			var html = ''
			for (var i = 0; i < dataArr.length; i++) {
				var oneData = dataArr[i]
				html +='<div class="schItem" data-index="'+i+'" data-desc="'+oneData['PostDesc']+'">'+oneData['PostDesc']+'</div>'
			}
			$('#'+scrollId)[0].innerHTML = html
			if (type == 'P') {
				zhiArr = dataArr
			}else if (type == 'H') {
				xiuArr = dataArr
			}else{
				allArr = dataArr
			}
		}, function(errorStr) {
			// mui.toast('请重试')
		});
	}
	
	function getCombineData(){
		var pdict = {"start":0,'limit':"",'WardID':wardID}
		var paramDict = {'method':'web.INMDBComm:FindWardPostGroupList','params':JSON.stringify(pdict),'type':'RecQuery'}
		//console.log(JSON.stringify(pdict))
		$.DHCWebService(paramDict, function(result) {
			//console.log(JSON.stringify(result))
			if (result['msgcode'] != '1') {
				mui.toast(result['msg'])
				$('#combineUL')[0].innerHTML = ''
				return
			}
			var dataArr = result['data']
			var html = ''
			for (var i = 0; i < dataArr.length; i++) {
				var oneData = dataArr[i]
				html += '<li class="mui-table-view-cell" data-id="'+oneData['rw']+'">'+oneData['GroupDesc']+'</li>'
			}
			var noZuHeTip = $('#noZuHeTip')[0]
			if (html == '') {
				noZuHeTip.style.display = 'block'
			}else{
				noZuHeTip.style.display = 'none'
			}
			$('#combineUL')[0].innerHTML = html
			
		}, function(errorStr) {
			mui.toast('请重试')
			
		});
	}
	function gotoNextTd(active,trIndex){
		var nextTd = active.nextElementSibling;
		if (nextTd) {
			mui.trigger(nextTd,'tap')
			return
		}
		var nextTr = active.parentNode.nextElementSibling;
		while (nextTr){
			var classStr = nextTr.getAttribute('class')
			if (classStr && classStr.indexOf('tr-nur') != -1) {
				var tds = nextTr.querySelectorAll('td')
				if (tds.length < 2) {
					return
				}
				nextTd = tds[1]
				mui.trigger(nextTd,'tap')
				return
			}
			nextTr = nextTr.nextElementSibling;
		}
	}
	
	function schFuncBtnsTapped(){
		if (this.id == 'upDownBtn') {
			upDownBtnTapped();
			return
		}
		if (this.id == 'moreBtn') {
			showOrHideMorePopover();
			return
		}
		// 点击其它按钮时隐藏更多按钮的弹框
		showOrHideMorePopover('hide');
		var active = getActiveSchDom()
		if (!active) {
			mui.toast('请先选择单元格')
			return
		}
		if (this.id == 'deleteBtn') {
			if (active.getAttribute('data-sch') == "") {
				return
			}
			deleteOneSch()
			return;
		}
		var pageName = this.getAttribute('data-page')
		if (pageName == '') {
			return
		}
		var schStr = active.getAttribute('data-sch')
		if (pageName == 'nurSchMark' && schStr == "%%") { //排班备注
			mui.toast('请先排班哦');
			return
		}
		var schStr = active.getAttribute('data-sch')
		var dateStr = active.getAttribute('data-day')
		var trIndex = active.parentNode.id.replace('row-','')
		var perInfo = locSchArr[trIndex]
		var ArgPerDR = perInfo['ArgPerDR']
		var ArgRowId =  perInfo['ArgRowId']
		var PerName = perInfo['PerName'].replace(perInfo['PerID'],"")
		var rw = ''
		if (argInfo) {
			rw = argInfo['rw']
		}
		var extras={'wardId':wardID,'sch':schStr,'date':dateStr,'ArgPerDR':ArgPerDR,'ArgRowId':ArgRowId,rw:rw,'PerName':PerName,'nurseid':nurseid}
		if (pageName == 'nurSchPlus' || pageName == 'nurSchAdd') { //加减班和追加班次
			extras['argInfo'] = argInfo
			extras['locSchArr'] = locSchArr;
			extras['index'] = trIndex
		}
		var webview = plus.webview.create(pageName+'.html', pageName, {
			background: '#fff',
			statusbar: {
				background: '#fff'
			}
		},{'sourceData':extras});
		webview.show('fade-in');
	}
	
	function upDownBtnTapped(flag){
		var body = document.body
		if (flag == 'hide') {
			body.classList.remove('dhc-active')
			return
		}else if (flag == 'show') {
			body.classList.add('dhc-active')
			return
		}
		var classStr = body.getAttribute('class');
		if (classStr.indexOf('dhc-active') != -1) {
			body.classList.remove('dhc-active')
		}else{
			body.classList.add('dhc-active')
		}
		mui('#locWrapper').scroll().reLayout();
	}
	function showOrHideMorePopover(flag){
		var moreSchPopover = $('#moreSchPopover')[0]
		if (flag == 'hide') {
			moreSchPopover.classList.remove('dhc-active')
			return
		}else if (flag == 'show') {
			moreSchPopover.classList.add('dhc-active')
			return
		}
		var classStr = moreSchPopover.getAttribute('class');
		if (classStr.indexOf('dhc-active') != -1) {
			moreSchPopover.classList.remove('dhc-active')
		}else{
			moreSchPopover.classList.add('dhc-active')
		}
	}
	function clearLocSchUI(){
		$('#schStatus')[0].setAttribute('class','nurfont schStatus'); //状态图标
		$('#locBody')[0].innerHTML = '' //排班详情
		$('#totalMark')[0].innerHTML = '' //整体备注
		$('#locWrapper').scroll().scrollTo(0,0,100);
		lastSelect = ''
		argInfo=undefined
		locSchArr=undefined
	}
	function updateSaveBtnShow(status){
		if (!isToSch) {
			return
		}
		var saveBtn = $('#saveBtn')[0]
		var commitBtn = $('#commitBtn')[0]
		switch (status){
			case "N":
				saveBtn.style.display = 'block'
				commitBtn.style.display = 'none'
				break;
			case "S":
				saveBtn.style.display = 'block'
				commitBtn.style.display = 'block'
				break;
			case "B":
				saveBtn.style.display = 'block'
				commitBtn.style.display = 'none'
				break;
			default:
				saveBtn.style.display = 'none'
				commitBtn.style.display = 'none'
				break;
		}
	}
	function getActiveSchDom(){
		var active = $('#locBody .mui-active')[0]
		return active
	}
	function getActiveSchDomIndex(){
		var active = $('#locBody .mui-active')[0]
		if (!active) {
			return ""
		}
		var trIndex = active.parentNode.id.split('-')[1]
		return trIndex
	}
	
	function showNullTip(msg,type){
		mui('#nullData')[0].style.display = 'block';
		mui('#nullTip')[0].innerHTML = msg
	}
	function hideNullTip(){
		mui('#nullData')[0].style.display = 'none';
	}
	var exportObj = {}
	exportObj.refreshZuHeData = function(){
		getCombineData();
	};
	exportObj.refreshLocSchData = function(){
		getLocSchData(); //更新排班
		//更新整体备注
	};
	exportObj.isExsitArg = function(){
		isExsitArg(); //整体更新
	};
	exportObj.createLocSchSheet = function(block){
		createNewArrange(block)
		//block(argInfo,locSchArr,1)
	};
	return exportObj
})(mui)

function refreshPageData(type,webviewId,funcName,otherParam){
	if (!type || type == 'zuhe') {
		schLocPage.refreshZuHeData()
	}else if (type == 'sch') {
		schLocPage.refreshLocSchData()
	}else if (type == 'create') { //新建排班表
		schLocPage.createLocSchSheet(function(argInfo,locSchArr,trIndex){
			var webview = plus.webview.getWebviewById(webviewId)
			if (webview) {
				if (otherParam) {
					if (trIndex == "") {
						trIndex='""'
					}
					//console.log(funcName+'('+JSON.stringify(argInfo)+','+JSON.stringify(locSchArr)+','+trIndex+','+JSON.stringify(otherParam)+')')
					webview.evalJS(funcName+'('+JSON.stringify(argInfo)+','+JSON.stringify(locSchArr)+','+trIndex+','+JSON.stringify(otherParam)+')')
					return
				}
				webview.evalJS(funcName+'('+JSON.stringify(argInfo)+','+JSON.stringify(locSchArr)+','+trIndex+')')
			}
		})
	}
}
function pageBackGetLocSchData(){
	schLocPage.isExsitArg()
}

/**排班参数————用于获取是周排班还是月排班等信息
 * ArgPeriod排班周期	Week:周排 Month:月排  ArgUpdateDay排班修改时限(天)  ArgStandardTime标准时长
 * ArgTimeSlot时段修改	true:允许 false:不允许  NightStTime1	夜班开始时间	  NightEndTime1	夜班结束时间	 rw	id	String
 * {"AMHour1":"","AMHour2":"","AdvInter":"A","ArgCountUnit":"","ArgCrossDay":"","ArgPeriod":"Week","ArgStandardTime":"8","ArgTimeSlot":"true",
 * "ArgUpdateDay":"14","BedBR":"0.4","Cycle":"20","DayHour1":"","DayHour2":"","InsertColumn":"2","IsAdvanced":"Y","NightEndTime1":"08:00",
 * "NightEndTime2":"08:00","NightStTime1":"18:00","NightStTime2":"18:00","NoticeDay":"1","NoticeShowDay":"1","NurMgInter":"E","NurMgOtherPort":"",
 * "NurMgOtherSever":"","NurMgOtherUrl":"","PMHour1":"","PMHour2":"","PlatFlag":"Y","RegNoLength":"10","SenFlag":"Y","StDate":"2022-01-01","rw":"1"}
 * 
 * 检查是否存在排班————msg的值>0是id ==0是不存在
 * ————0是不存在排班,需要检查上周排班,如果上周有排班则提示复制上周排班,上周不存在排班则显示人员列表
 * ————值>0是排班表id 去获取排班表信息
 * ArgAuthorHours:授权小时数	    ArgCrtDate:创建日期    ArgCrtTime:创建时间    ArgCrtUpdateLog:是否存在修改记录    ArgCrtUser:创建人user id
 * ArgCurrentWeek:排班表周数    ArgEditFlag:申请状态:S申请 A授权    ArgEndDate:结束日期    ArgListNo:排班表号    ArgOtherRemark:其他备注
 * ArgRemarks:备注「为换行符    ArgStDate:开始日期    ArgStatus:状态N草稿 S保存未提交 R提交 A审核 B驳回    ArgWardDR:病区id    CrtUserName:创建人姓名
 * EditFlagDesc:申请状态描述    WardDesc:病区描述    rw:id
 * {"ArgAuthorHours":"","ArgCrtDate":"2022-03-28","ArgCrtTime":"07:54:44","ArgCrtUpdateLog":"否","ArgCrtUser":"0",
 * "ArgCurrentWeek":"第14周","ArgEditFlag":"N","ArgEndDate":"2022-04-10","ArgListNo":"2022040429","ArgOtherRemark":",,,,,,,,,,,,,,,,,,,,",
 * "ArgRemarks":"","ArgStDate":"2022-04-04","ArgStatus":"N","ArgWardDR":"29","CrtUserName":"管理员","EditFlagDesc":"",
 * "StatusDesc":"草稿","WardDesc":"内分泌科护理单元","rw":"164"}
 * 
 * {"PerName":"张璐诗4095","PerID":"4095","WorlYear":"14","ArgPerDR":"676","ArgRowId":"2602","ArgPerSort":"1","LevelDesc":"N2","GrpDesc":"","GrpSort":"1",
 * "isEditPost":"0","PerSort":"1","PerPost":"","ArgGroupDR":"-","ArgWorkRemark":"","ArgPerBeds":"",
 * "Date2022-03-30":"4748」事假请假半天『「4749」P请假半天『07:30-11:30;次日14:00-次日18:00%%","ArgTotalHour":"32时0分",
 * "ArgNightHour":"0时0分","ArgSecondHour":"0时0分","PerCode":"","ArgProductHour":"4.0","ArgAllProductHour":"-316.0","remarkedit":"0","bededit":"0"}
 * 
 * "Date2022-03-28":"4740」A『08:00-16:00%%",
 * "Date2022-03-29":"4743」P『07:30-11:30;14:00-18:00%%",
 * "Date2022-03-30":"4748」事假请假半天『「4749」P请假半天『07:30-11:30;次日14:00-次日18:00%%",
 * "Date2022-03-31":"4852」A『08:00-16:00%%",
 * 组合
 * {"GroupDesc":"22","GroupWard":"29","GroupWardDesc":"内分泌科护理单元","GroupPost":"74,73,70","GroupPostDesc":"行政班,医嘱班,事假","rw":"3"}
 */


//人员删除 删不了会出现在排班的最下方ArgRowId为空,且还会排班;
//处理ArgRowId为空的人员的排班